﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace T.FAS.Runtime.Base.Entity
{
    [DataContract]
    [Serializable]
    [JsonConverter(typeof(AbsElementJsonConverter))]
    public class Group : AbsElement
    {
        [DataMember]
        public override string ElementType { get { return "Group"; } }

        [DataMember]
        public AdvancedFilterExtSetting ExtSetting { get; set; }

        [DataMember]
        public List<AbsElement> Filters { get; set; }

        public void AddFilter(Filter filter)
        {
            Filters = new List<AbsElement>
            {
                filter
            };
        }

        public void AddFilter(FRelation releation, Filter filter)
        {
            Filters.Add(releation);
            Filters.Add(filter);
        }

        public void AddFilter(Group group)
        {
            Filters = new List<AbsElement>
            {
                group
            };
        }

        public void AddFilter(FRelation releation, Group group)
        {
            Filters.Add(releation);
            Filters.Add(group);
        }

        public override string ToDisplayString()
        {
            string result = string.Empty;
            foreach (var filter in Filters)
            {
                result += filter.ToDisplayString();
            }
            return "(" + result + ")";
        }

        public override string ToValueString()
        {
            string result = string.Empty;
            foreach (var filter in Filters)
            {
                result += filter.ToValueString();
            }
            return "(" + result + ")";
        }
    }

    [DataContract]
    [Serializable]
    public class AdvancedFilterExtSetting
    {
        [DataMember]
        public List<GroupColumn> GroupColumns { get; set; }

        [DataMember]
        public Dictionary<string, object> ExtParams { get; set; }
    }

    [DataContract]
    [Serializable]
    public class GroupColumn
    {
        [DataMember]
        public string Code { get; set; }
    }
}